/*******************************************************************************
 * Copyright (C) 2010 Devin Samarin.
 * 
 * This file is part of the SUIT Toolkit.
 * 
 * The SUIT Toolkit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * The SUIT Toolkit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with the SUIT Toolkit.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package suit.ui;

import javax.microedition.lcdui.Graphics;

public class Gradient {

	public Color a;
	public Color b;

	public int orient;
	public Rectangle bounds;

	public static final int Horiz = 1;
	public static final int Vert = 2;

	// private boolean dither;

	public Gradient(Color a, Color b) {
		this.a = a;
		this.b = b;
		// this.dither = false;
	}

	public void paint(Graphics g, Rectangle bounds, int orient) {
		int max = ((orient == Vert) ? bounds.h : bounds.w);
		if( max == 0 ) return;
		for (int i = 0; i < max; i++) {
			int color = a.blend(b, ((float) i / (float) (max - 1))).value();
			g.setColor(color);
			if (orient == Vert)
				g.drawLine(bounds.x, bounds.y + i, bounds.x + bounds.w,
						bounds.y + i);
			else
				g.drawLine(bounds.x + i, bounds.y, bounds.x + i, bounds.y
						+ bounds.h);
		}
	}
}
